package com.hospital.hospitaldrugservice.web;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hospital.common.dto.DrugDto;
import com.hospital.common.vo.ResultEntity;
import com.hospital.hospitaldrugservice.entity.Drug;
import com.hospital.hospitaldrugservice.service.IDrugService;
import com.sun.org.apache.xerces.internal.util.EntityResolverWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 药品表 前端控制器
 * </p>
 *
 * @author 王晓康
 * @since 2020-10-20
 */
@RestController
@RequestMapping("/drug")
public class DrugController {

    @Autowired
    private IDrugService drugService;

    @RequestMapping("/addDrug")
    public ResultEntity addDrug(@RequestBody DrugDto dto){
        drugService.addDrug(dto);
        return ResultEntity.ok();
    }

    @RequestMapping("/getLastDrugnumber")
    public ResultEntity getLastDrugnumber(){
        return ResultEntity.ok(drugService.getLastDrugnumber());
    }

    @RequestMapping("/updDrug")
    public ResultEntity updDrug(@RequestBody DrugDto dto){
        drugService.updDrug(dto);
        return ResultEntity.ok();
    }

    @RequestMapping("/list")
    public ResultEntity list(Page page, DrugDto dto){
        IPage<Drug> drugList = drugService.selectPageDto(page, dto);
        return ResultEntity.ok(drugList);
    }

}
